The approaches described in this section are approaches that could be pursued, but not necessarily approaches that have been previously conceived or pursued. Therefore, unless otherwise indicated, it should not be assumed that any of the approaches described in this section qualify as prior art merely by virtue of their inclusion in this section.
Binary instrumentation as referred to herein is the process of inserting additional code into a set of executable code. The additional code is designed to generate profile information that provides an insight in the execution of the set of executable code. For example, profile information generated by such additional code may indicate the most frequently executed portions of the set of executable code. Profile information about the set of executable code may be used to guide any subsequent optimization of the most frequently executed portions of the code and to improve the overall run-time performance.
Binary instrumentation is typically performed on binary files. A binary (or executable) file as referred to herein is a file that stores the set of executable instructions for a computer program. Binary instrumentation usually involves identifying the executable code section (or code segment) of the computer program, disassembling some or all of the code section, and inserting instrumentation code at one or more points (or locations) in the code section of the program. For example, during binary instrumentation, instrumentation code may be inserted at a particular point in the executable code of a computer program that is stored in the binary file being instrumented. During the execution of the computer program, each time the instrumentation code is executed, the instructions in the instrumentation code cause a counter to be incremented. Thus, when the execution of the computer program is complete, the counter would indicate the number of times that the portion of the computer program incorporating the particular point was executed.
The presently available binary instrumentation techniques use heuristics and/or assumptions about the source code and the structure of a computer program in order to determine the points in the program at which to insert instrumentation code. Using heuristics and assumptions to determine where in a computer program to insert the instrumentation code has several disadvantages.
One such disadvantage is that since the heuristics and the assumptions about a computer program may not always be correct, the presently available binary instrumentation techniques are not reliable and robust in all cases and cannot guarantee the correctness of any profile information generated by executing an instrumented binary file. For this reason, the presently available commercial binary instrumentation tools typically warn its users that binary files instrumented with the tools may exhibit unexpected behavior when executed. Furthermore, since the profile information generated by executing such instrumented binary files is not accurate, such profile information cannot be reliably used to analyze and further optimize the computer program.
Another disadvantage of using heuristics and assumptions to determine where in a computer program to insert the instrumentation code are the high run-times of instrumented binary files. Since the heuristics and assumptions are not always correct, instrumentation code is typically inserted in more places in the computer program than necessary. This results in the execution of a larger number of unnecessary instructions when the instrumented binary file is executed. Furthermore, any instrumentation code inserted in a binary file must include additional instructions to save and restore registers used by the instrumentation code in order to preserve the proper context and flow of execution of the computer program.